package web.fabrimind.sm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.sm.domain.ProductionShift;
import web.fabrimind.sm.service.IProductionShiftService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 生产班次Controller
 * 
 * @author zhihui
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/sm/shift")
public class ProductionShiftController extends BaseController
{
    @Autowired
    private IProductionShiftService productionShiftService;

    /**
     * 查询生产班次列表
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionShift productionShift)
    {
        startPage();
        List<ProductionShift> list = productionShiftService.selectProductionShiftList(productionShift);
        return getDataTable(list);
    }

    /**
     * 导出生产班次列表
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:export')")
    @Log(title = "生产班次", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionShift productionShift)
    {
        List<ProductionShift> list = productionShiftService.selectProductionShiftList(productionShift);
        ExcelUtil<ProductionShift> util = new ExcelUtil<ProductionShift>(ProductionShift.class);
        util.exportExcel(response, list, "生产班次数据");
    }

    /**
     * 获取生产班次详细信息
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:query')")
    @GetMapping(value = "/{shiftId}")
    public AjaxResult getInfo(@PathVariable("shiftId") Long shiftId)
    {
        return success(productionShiftService.selectProductionShiftByShiftId(shiftId));
    }

    /**
     * 新增生产班次
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:add')")
    @Log(title = "生产班次", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionShift productionShift)
    {
        return toAjax(productionShiftService.insertProductionShift(productionShift));
    }

    /**
     * 修改生产班次
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:edit')")
    @Log(title = "生产班次", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionShift productionShift)
    {
        return toAjax(productionShiftService.updateProductionShift(productionShift));
    }

    /**
     * 删除生产班次
     */
    @PreAuthorize("@ss.hasPermi('sm:shift:remove')")
    @Log(title = "生产班次", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shiftIds}")
    public AjaxResult remove(@PathVariable Long[] shiftIds)
    {
        return toAjax(productionShiftService.deleteProductionShiftByShiftIds(shiftIds));
    }
}
